package com.example.cqcet_demo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.cqcet_demo.R;

import java.util.List;

/**
 * Created by Mr.z on 2017/6/19.
 */

public class MyListViewUserInfoAdapter extends BaseAdapter{
    private List<String> userInfos;
    private Context context;

    public MyListViewUserInfoAdapter(Context context,List userInfos){
        this.context = context;
        this.userInfos = userInfos;
    }

    @Override
    public int getCount() {
        return userInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return userInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder;
        if(convertView==null){
            convertView = View.inflate(context, R.layout.userinfo_item,null);
            viewHoder = new MyListViewUserInfoAdapter.ViewHoder();
            viewHoder.userInfoKey = (TextView)convertView.findViewById(R.id.userInfoKey);
            viewHoder.userInfoValue = (TextView)convertView.findViewById(R.id.userInfoValue);
            convertView.setTag(viewHoder);
        }else{
            viewHoder = (MyListViewUserInfoAdapter.ViewHoder) convertView.getTag();
        }
        String[] arr = userInfos.get(position).split(":");
        viewHoder.userInfoKey.setText(arr[0]);
        viewHoder.userInfoValue.setText(arr[1]);

        return convertView;
    }
    static class ViewHoder{
        TextView userInfoKey;
        TextView userInfoValue;
    }
}
